package heima_design.model10;
/**
 * @ClassName: Singleton
 * @Description: 反射破坏单例模式
 * @Version: v1.0.0
 * @Author: tamir
 * @Date: 2022/06/02
 * Modification History:
 * Date             Author      Version     Description
 * -------------------------------------------------------------
 * 2022/06/02      tamir        v1.0.0      创建
 */
public class Singleton {

    //私有构造方法
    private Singleton() {}
    
    private static volatile Singleton instance;

    //对外提供静态方法获取该对象
    public static Singleton getInstance() {

        if(instance != null) {
            return instance;
        }

        synchronized (Singleton.class) {
            if(instance != null) {
                return instance;
            }
            instance = new Singleton();
            return instance;
        }
    }
}